package com.gujiangbo.reference;

import java.lang.ref.WeakReference;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/3/12 09:37
 * @Version: 1.0
 * @Description: 弱引用，有gc就被回收
 */
public class WeekReferenceDemo {

    public static void main(String[] args) {
        Object obj = new Object();
        WeakReference<Object> weakReference = new WeakReference<>(obj);
        System.out.println(obj);
        System.out.println(weakReference.get());

        obj = null;
        System.gc();
        System.out.println("=========");

        System.out.println(obj);
        System.out.println(weakReference.get());


    }
}
